package fr.infomee.blou.EwOkArena;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import fr.infomee.blou.EwOkArena.stuff.StuffAbstract;
import fr.infomee.blou.EwOkArena.stuff.StuffArcOnly;
import fr.infomee.blou.EwOkArena.stuff.StuffBdn;
import fr.infomee.blou.EwOkArena.stuff.StuffCuir;
import fr.infomee.blou.EwOkArena.stuff.StuffDiamond;
import fr.infomee.blou.EwOkArena.stuff.StuffFinal;
import fr.infomee.blou.EwOkArena.stuff.StuffGold;
import fr.infomee.blou.EwOkArena.stuff.StuffIron;
import fr.infomee.blou.EwOkArena.stuff.StuffLot1;
import fr.infomee.blou.EwOkArena.stuff.StuffLot2;
import fr.infomee.blou.EwOkArena.stuff.StuffLot3;
import fr.infomee.blou.EwOkArena.stuff.StuffLot4;
import fr.infomee.blou.EwOkArena.stuff.StuffLot5;
import fr.infomee.blou.EwOkArena.stuff.StuffTnt;
import fr.infomee.blou.EwOkArena.stuff.StuffVide;
import fr.infomee.blou.EwOkArena.zone.Zone;

public class Outils {

	
	
	public static StuffAbstract getStuff(String param){
		StuffAbstract stuff = null;
		if(param.equals("rdm")){
			List<String> allStuffForRandom = new ArrayList<String>();
			allStuffForRandom.add("cuir");
			allStuffForRandom.add("iron");
			allStuffForRandom.add("gold");
			allStuffForRandom.add("diamond");
			allStuffForRandom.add("arc");
			allStuffForRandom.add("final");
			Collections.shuffle(allStuffForRandom);
			stuff = Outils.getStuff(allStuffForRandom.get(1));
		}
		if(param.equals("cuir")){
			stuff = new StuffCuir();
		}
		else if(param.equals("iron")){
			stuff = new StuffIron();
		}
		else if(param.equals("gold")){
			stuff = new StuffGold();
		}
		else if(param.equals("diamond")){
			stuff = new StuffDiamond();
		}
		else if(param.equals("arc")){
			stuff = new StuffArcOnly();
		}
		else if(param.equals("lot1")){
			stuff = new StuffLot1();
		}
		else if(param.equals("lot2")){
			stuff = new StuffLot2();
		}
		else if(param.equals("lot3")){
			stuff = new StuffLot3();
		}
		else if(param.equals("lot4")){
			stuff = new StuffLot4();
		}
		else if(param.equals("lot5")){
			stuff = new StuffLot5();
		}
		else if(param.equals("vide")){
			stuff = new StuffVide();
		}
		else if(param.equals("final")){
			stuff = new StuffFinal();
		}
		else if(param.equals("bdn")){
			stuff = new StuffBdn();
		}
		else if(param.equals("tnt")){
			stuff = new StuffTnt();
		}

		return stuff;
	}
	
	
	
	public static void stuffPlayer(Player player, StuffAbstract stuff){

		player.getInventory().clear();
		if(stuff.getHelmet() != null) {
			player.getInventory().setHelmet(stuff.getHelmet().clone());
		}
		else{
			player.getInventory().setHelmet(null);
		}
		if(stuff.getChestplate() != null) {
			player.getInventory().setChestplate(stuff.getChestplate().clone());
		}
		else{
			player.getInventory().setChestplate(null);
		}
		if(stuff.getLeggings() != null)  {
			player.getInventory().setLeggings(stuff.getLeggings().clone());
		}
		else{
			player.getInventory().setLeggings(null);
		}
		if(stuff.getBoots() != null) {
			player.getInventory().setBoots(stuff.getBoots().clone());
		}
		else{
			player.getInventory().setBoots(null);
		}
		for(ItemStack item : stuff.getStuff()){
			player.getInventory().addItem(item.clone());
		}

	}
	
	
	public static boolean isPlayerOnZone(Player player, Zone zone){
		
		Location loc = player.getLocation();

		if(!loc.getWorld().getName().equals(EwOkArena.map)){
			return false;
		}
		

		double yPlayer = loc.getY();
		if (yPlayer < zone.getYmin() || yPlayer > zone.getYmax()) {
			return false;
		}

		double zPlayer = loc.getZ();
		double xPlayer = loc.getX();
		if (zPlayer > zone.getZmin() && zPlayer < zone.getZmax()+1  
			&& xPlayer > zone.getXmin() && xPlayer < zone.getXmax()+1) {
			return true;
		}


		return false;
		
		
		
	}
	
}
